反转链表

反转链表

题目描述

输入一个链表,反转链表后,输出新链表的表头。

1
2
3
4
5
6
7
8
9
10
11
12
13
function ReverseList(pHead)
{
// write code here
var pNode=null;
var pNext=null;
while(pHead!==null){
pNext=pHead.next;
pHead.next=pNode;
pNode=pHead;
pHead=pNext;
}
return pNode;
}